import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { useUserStore } from '@/store/modules/user';
import { unref } from 'vue';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '提货点',
    align: 'center',
    dataIndex: 'pickUpId_dictText',
  },
  {
    title: '商品',
    align: 'center',
    dataIndex: 'skuId_dictText',
  },
  {
    title: '实际库存',
    align: 'center',
    dataIndex: 'actualStock',
  },
  {
    title: '锁定库存',
    align: 'center',
    dataIndex: 'stocks',
  },
  {
    title: '状态',
    align: 'center',
    dataIndex: 'status_dictText',
  },
];

const userStore = useUserStore();
const orgCode = unref(userStore.getUserInfo).orgCode;
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '提货点',
    field: 'pickUpId',
    component: 'JSearchSelect',
    componentProps: {
      dict: `uf_mall_pick_up_point,name,id,sys_org_code='${orgCode}' AND del_flag = 0`,
    },
  },
  {
    label: '商品',
    field: 'skuId',
    component: 'JSearchSelect',
    componentProps: {
      dict: `uf_mall_sku,sku_name,id,sys_org_code='${orgCode}' AND del_flag = 0`,
    },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '提货点',
    field: 'pickUpId',
    component: 'JSearchSelect',
    componentProps: {
      dict: `uf_mall_pick_up_point,name,id,sys_org_code='${orgCode}' AND del_flag = 0`,
      getPopupContainer: () => document.body,
    },
    required: true,
  },
  {
    label: '商品',
    field: 'skuId',
    component: 'JSearchSelect',
    componentProps: {
      dict: `uf_mall_sku,sku_name,id,sys_org_code='${orgCode}' AND del_flag = 0`,
      getPopupContainer: () => document.body,
    },
    required: true,
  },
  {
    label: '实际库存',
    field: 'actualStock',
    component: 'InputNumber',
    required: true,
  },
  {
    label: '状态',
    field: 'status',
    component: 'JDictSelectTag',
    defaultValue: '0',
    componentProps: {
      dictCode: 'goods_status',
    },
    required: true,
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

//表单数据
export const batchFormSchema: FormSchema[] = [
  {
    label: '提货点',
    field: 'pickUpId',
    component: 'JSearchSelect',
    componentProps: {
      dict: `uf_mall_pick_up_point,name,id,sys_org_code='${orgCode}' AND del_flag = 0`,
      getPopupContainer: () => document.body,
    },
    required: true,
  },
  {
    label: '商品',
    field: 'skuId',
    component: 'JSelectMultiple',
    componentProps: {
      dictCode: `uf_mall_sku,sku_name,id,sys_org_code='${orgCode}' AND del_flag = 0`,
      getPopupContainer: () => document.body,
    },
    required: true,
  },
  {
    label: '实际库存',
    field: 'actualStock',
    component: 'InputNumber',
    required: true,
  },
  {
    label: '状态',
    field: 'status',
    component: 'JDictSelectTag',
    defaultValue: '0',
    componentProps: {
      dictCode: 'goods_status',
    },
    required: true,
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];
// 高级查询数据
export const superQuerySchema = {
  pickUpId: { title: '提货点', order: 0, view: 'sel_search', type: 'string', dictCode: '' },
  skuId: { title: '商品', order: 1, view: 'sel_search', type: 'string', dictCode: '' },
  actualStock: { title: '实际库存', order: 2, view: 'number', type: 'number' },
  stocks: { title: '锁定库存', order: 3, view: 'number', type: 'number' },
  status: { title: '状态', order: 4, view: 'text', type: 'string' },
};

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
